from db_conn.getBy import getByProvinceAndYear


#生成饼图的数据处理和封装层
def getComTypeCnt_PY(province,year):
    data=getByProvinceAndYear(province, year)
    school=0
    company=0
    graduate=0
    hospital=0
    others=0
    for d in data:
        if d[2] != None:
            d2 = d[2].split('、')
            for com in d2:
                if '大学'in com:
                    school=school+1
                elif '公司'in com:
                    company=company+1
                elif '研究' in com:
                    graduate=graduate+1
                elif '医院' in com:
                    hospital=hospital+1
                else:others=others+1
    list=[]

    dict={}
    dict['name']='大学'
    dict['value']=school
    list.append(dict)

    dict={}
    dict['name']='公司'
    dict['value']=company
    list.append(dict)

    dict={}
    dict['name']='研究机构'
    dict['value']=graduate
    list.append(dict)

    dict={}
    dict['name']='医院'
    dict['value']=hospital
    list.append(dict)

    dict={}
    dict['name']='其他单位'
    dict['value']=others
    list.append(dict)

    print(list)
    return list

def getComTypeCntService(province):
    res={}
    for year in range(2021,2024):
        data=getComTypeCnt_PY(province,year)
        res[year]=data
    print(res)
    return res
if __name__ == '__main__':
    getComTypeCntService('黑龙江')